package edu.nazarevych.portal.tools;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

public class JSONChartData {
	
//mvn install:install-file -Dfile=C:\json-lib-2.4-jdk15.jar -DgroupId=net.sf.json-lib -DartifactId=json-lib -Dversion=2.4 -Dpackaging=jar
	
	public static JSONObject getJson (){
		
		JSONObject json = new JSONObject();
		JSONObject col = new JSONObject();
		JSONObject row = new JSONObject();
		Map<String, Object> rowValues = new HashMap<String, Object>();
		col.put(ID, "Col1");
		col.put(LABEL, "Column 1");
		col.put(TYPE, TYPE_NUMBER);
		json.accumulate(COLUMNS, col);
		col.clear();
		col.put(ID, "Col2");
		col.put(LABEL, "Column 2");
		col.put(TYPE, TYPE_NUMBER);
		json.accumulate(COLUMNS, col);
		col.clear();
		col.put(ID, "Col3");
		col.put(LABEL, "Column 3");
		col.put(TYPE, TYPE_NUMBER);
		json.accumulate(COLUMNS, col);
		col.clear();
		// rows
		rowValues.put(CELL_VALUE, Integer.valueOf(1));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(224));
		rowValues.put(CELL_VALUE_FORMATTED, "formatted text");
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(934));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		json.accumulate(ROWS, row);
		row.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(2));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(3224));
		rowValues.put(CELL_VALUE_FORMATTED, "formatted text");
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(2934));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		json.accumulate(ROWS, row);
		row.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(3));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(324));
		rowValues.put(CELL_VALUE_FORMATTED, "formatted text");
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(4534));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		json.accumulate(ROWS, row);
		row.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(4));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(243));
		rowValues.put(CELL_VALUE_FORMATTED, "formatted text");
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(784));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		json.accumulate(ROWS, row);
		row.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(5));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(224));
		rowValues.put(CELL_VALUE_FORMATTED, "formatted text");
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		rowValues.put(CELL_VALUE, Integer.valueOf(934));
		row.accumulate(CELL, rowValues);
		rowValues.clear();
		json.accumulate(ROWS, row);
		
		return json;
	}

	private static final String COLUMNS = "cols";
	private static final String ROWS = "rows";
	private static final String ID = "id";
	private static final String LABEL = "label";
	private static final String TYPE = "type";
	private static final String TYPE_STRING = "string";
	private static final String TYPE_NUMBER = "number";
	private static final String TYPE_DATE= "date";
	private static final String CELL = "c";
	private static final String CELL_VALUE = "v";
	private static final String CELL_VALUE_FORMATTED = "f";
}
